﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Comdiv.QWeb.Diagnostics;
using NUnit.Framework;

namespace Comdiv.QWeb.Test.SystemActions
{
	[TestFixture]
	public class Stats_test
	{
		[Test]
		public void check_stats() {
			var reg = new QWebServiceRegistry();
			new QWebHandler(reg).ProcessRequest(new QWebContext("http://server/qweb/echo.qweb"));
			new QWebHandler(reg).ProcessRequest(new QWebContext("http://server/qweb/echo.xml.qweb"));
			new QWebHandler(reg).ProcessRequest(new QWebContext("http://server/qweb/echo.json.qweb"));
			new QWebHandler(reg).ProcessRequest(new QWebContext("http://server/qweb/echo.json.qweb"));
			var t = new QWebHandler(reg).ProcessRequest(new QWebContext("http://localhost/qweb/stats.xml.qweb"));
			Assert.IsInstanceOf<IQWebStatistics>(t.ActionResult);
			var s = (IQWebStatistics) t.ActionResult;
			Assert.AreEqual(4, s.ActionStats["qweb.echo"].Activations);
			Assert.AreEqual(1, s.ActionStats["qweb.echo"].Creations);
			Assert.AreEqual(1, s.ActionStats["qweb.echo"].PoolSize);
			Assert.AreEqual(1, s.ActionStats["qweb.stats"].Activations);
			Assert.AreEqual(1, s.ActionStats["qweb.echo"].Creations);
			Assert.AreEqual(1, s.ActionStats["qweb.echo"].PoolSize);
			Assert.AreEqual(1, s.RenderStats["js"].Activations);
			Assert.AreEqual(2, s.RenderStats["json"].Activations);
			Assert.AreEqual(2, s.RenderStats["xml"].Activations);
		} 
	}
}
